home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / XLIB06.ZIP / XMOUSE.ASM < prev    next >
Assembly Source File  |  1993-10-06  |  24KB  |  885 lines

  1. ;-----------------------------------------------------------------------
  2. ; MODULE XMOUSE
  3. ;
  4. ; Mouse functions functions for all MODE X 256 Color resolutions
  5. ;
  6. ; Compile with Tasm.
  7. ; C callable.
  8. ;
  9. ; ****** XLIB - Mode X graphics library                ****************
  10. ; ******                                               ****************
  11. ; ****** Written By Themie Gouthas                     ****************
  12. ;
  13. ; This module is based on Shane Hyde's module of the same name,
  14. ; posted to Rec.Games.Programmer, October 92.
  15. ;
  16. ;
  17. ; egg@dstos3.dsto.gov.au
  18. ; teg@bart.dsto.gov.au
  19. ;
  20. ; mouse cursor shape by Tiaan A Geldenhuys
  21. ;
  22. ;-----------------------------------------------------------------------
  23.  
  24. COMMENT  $
  25.  
  26.  
  27. This is a module implementing very basic mouse functions.
  28.  
  29. It does not support the full functionality of:
  30.  
  31.   SPLIT SCREENS
  32.   SCROLLED WINDOWS
  33.   VIRTUAL WINDOWS
  34.  
  35.           --------------------------------------
  36.  
  37.           MS Mouse Driver Functions
  38.  
  39.           Mouse Initialization                 0
  40.           Show Cursor                          1
  41.           Hide Cursor                          2
  42.           Get Mouse Position & Button Status   3
  43.           Set Mouse Cursor Position            4
  44.           Get Button Press Information         5
  45.           Get Button Release Information       6
  46.           Set Min/Max Horizontal Position      7
  47.           Set Min/Max Vertical Position        8
  48.           Define Graphics Cursor Block         9
  49.           Define Text Cursor                  10
  50.           Read Mouse Motion Counters          11
  51.           Define Event Handler                12
  52.           Light Pen Emulation Mode ON         13
  53.           Light Pen Emulation Mode OFF        14
  54.           Set Mouse Mickey/Pixel Ratio        15
  55.           Conditional Hide Cursor             16
  56.           Set Double-Speed Threshold          19
  57.           --------------------------------------
  58. $
  59.  
  60. include xlib.inc
  61. include xdetect.inc
  62.  
  63. .data
  64.  
  65. global   _MouseInstalled    :word
  66. global   _MouseHidden       :word
  67. global   _MouseButtonStatus :word
  68. global   _MouseX            :word
  69. global   _MouseY            :word
  70. global   _MouseFrozen       :byte
  71. global   _MouseColor        :byte
  72.  
  73. global   _x_define_mouse_cursor :proc
  74. global   _x_show_mouse          :proc
  75. global   _x_hide_mouse          :proc
  76. global   _x_mouse_remove        :proc
  77. global   _x_position_mouse      :proc
  78. global   _x_put_cursor          :proc
  79. global   _x_update_mouse        :proc
  80. global   _x_mouse_init          :proc
  81. global   _x_mouse_window        :proc
  82.  
  83.  
  84. ALIGN 2
  85.  
  86.  
  87.  
  88.       InitMouseDef db 00000001b  ; Default mouse mask, note the reverse order
  89.         db 00000011b
  90.         db 00000111b
  91.         db 00001111b
  92.         db 00011111b
  93.         db 00111111b
  94.         db 01111111b
  95.         db 11111111b
  96.         db 00011111b
  97.         db 00011011b
  98.         db 00110001b
  99.         db 00110000b
  100.         db 01100000b
  101.         db 01100000b
  102.  
  103.  
  104.  
  105. COMMENT $
  106.  
  107.    Old mouse definition
  108.  
  109.    InitMouseDef db 00000001b  ; Default mouse mask, note the reverse order
  110.         db 00000011b
  111.         db 00000111b
  112.         db 00001111b
  113.         db 00011111b
  114.         db 00111111b
  115.         db 01111111b
  116.         db 11111111b
  117.         db 00011100b
  118.         db 00111100b
  119.         db 01111100b
  120.         db 00000000b
  121.         db 00000000b
  122.         db 00000000b
  123.  
  124. $
  125.  
  126.     MouseMask          db 168 dup(?)
  127.     OldHandlerSeg      dw  ?
  128.     OldHandlerOffs     dw  ?
  129.     OldHandlerMask     dw  ?
  130.     OldX               dw  ?
  131.     OldY               dw  ?
  132.     OldScrnOffs        dw  ?
  133.  
  134.     BGSaveOffs         dw  0
  135.  
  136.    _MouseInstalled     dw 0     ; Flag indicating whether mouse is installed
  137.    _MouseHidden        dw 0     ; Flag indicating whether mouse is hidden
  138.    _MouseButtonStatus  dw 0     ; Holds current button press information
  139.    _MouseX             dw 0     ; Coords of cursor hot spot
  140.    _MouseY             dw 0
  141.    _MouseFrozen        db 0     ; Mouse motion enable/disable control
  142.    _MouseColor         db 0     ; Mouse cursor colour
  143.  
  144.    inhandler           db 0
  145. .code
  146.  
  147. ;----------------------------------------------------------------------
  148. ; Local function that updates the cursor position
  149. ;
  150. ; Destroys SI,DI,AX,BX
  151. ;
  152. ;----------------------------------------------------------------------
  153. proc update_cursor near
  154.    WaitVsyncStart
  155.  
  156.    mov di,[OldScrnOffs]             ; Delete cursor (restore old background)
  157.    mov ax,[OldY]
  158.    mov bx,[OldX]
  159.  
  160.    call restorebg
  161.  
  162.    mov si,[_VisiblePageOffs]        ; Save cursor background
  163.    mov ax,[_MouseY]
  164.    mov bx,[_MouseX]
  165.    mov [OldScrnOffs],si
  166.    mov [OldY],ax
  167.    mov [OldX],bx
  168.    call getbg
  169.  
  170.    push [_VisiblePageOffs]          ; Draw the cursor
  171.    mov  ax,[_ScrnPhysicalHeight]
  172.    push ax
  173.    mov  ax,0
  174.    push ax
  175.    push [OldY]
  176.    push [OldX]
  177.    call _x_put_cursor
  178.    add  sp,10
  179.    ret
  180. update_cursor endp
  181.  
  182.  
  183. ;----------------------------------------------------------------------
  184. ; x_mouse_init - Initialise Mode X mouse handler
  185. ;
  186. ; C Prototype
  187. ;
  188. ;  int x_mouse_init()
  189. ;
  190. ; This is the first function you must call before using any of the mouse
  191. ; functions
  192. ;
  193. ; WARNING: This function uses and updates "NonVisual_Offset" to allocate
  194. ;          video ram for the saved mouse background.
  195. ;
  196. ; This mouse code uses the fastest possible techniques to save and restore
  197. ; mouse backgrounds and to draw the mouse cursor.
  198. ;
  199. ; LIMITATIONS: No clipping is supported horizontally for the mouse cursor
  200. ;              No validity checking is performed for NonVisual_Offs
  201. ;
  202. ;
  203. ; **WARNING** Hide or freeze mouse while drawing using any of the other
  204. ;             Modules. VGA register settings are not preserved which will
  205. ;             result in unpredictable drawing behavior.
  206. ;             If you know the drawing will occur away from the mouse cursor
  207. ;             set MouseFrozen to TRUE (1), do your drawing then set it to
  208. ;             FALSE (0). Alternatively call "x_hide_mouse", perform your
  209. ;             drawing and then call "x_show_mouse"
  210. ;
  211. ;
  212. ; Written by Themie Gouthas
  213. ;----------------------------------------------------------------------
  214. _x_mouse_init proc
  215.      push  bp
  216.      mov   bp,sp
  217.  
  218.      cmp   [_MouseButtonCount],0  ; Dont initialize if mouse detection
  219.      jne   @@DontInitialize       ; or initialization function previously
  220.                   ;   called
  221.      xor   ax,ax                  ; FUNC 0: Mouse Initialization
  222.      int   33h                    ;
  223.      or    ax,ax                  ; Is there a mouse installed ?
  224.      jz    @@Done
  225.      mov   [_MouseButtonCount],bx ; Set the button count
  226.  
  227. @@DontInitialize:
  228.  
  229.      mov   [_MouseInstalled],ax
  230.      or    ax,ax                  ; Do we have an installed mouse driver ?
  231.      jz    @@Done                 ; Nop!
  232.  
  233.      mov   ax,[_NonVisual_Offs];  ; Allocate VRAM for saved background
  234.      mov   BGSaveOffs,ax
  235.  
  236.      add   ax,14*3
  237.      mov   [_NonVisual_Offs],ax   ; Update NonVisualOffset
  238.  
  239.      mov   ax,02                  ; FUNC 2: Hide Cursor
  240.      int   33h                    ;  (hide the mouse driver's default cursor)
  241.      mov   _MouseInstalled,TRUE   ; Indicate user mouse driver present
  242.  
  243.      mov   ax,07h                 ; FUNC 7:Set min/max horizontal position
  244.      mov   cx,0
  245.      mov   dx,[_ScrnPhysicalPixelWidth]
  246.      shl   dx,1                   ; Mult X by 2 as cursor steps by 2 pixels
  247.      int   33h                    ; 0 < X < _ScrnPhysicalPixelWidth
  248.  
  249.      mov   ax,08h                 ; FUNC 8:Set min/max vertical position
  250.      mov   cx,0
  251.      mov   dx,_ScrnPhysicalHeight
  252.      int   33h                    ; 0 < Y < _ScrnPhysicalHeight
  253.  
  254.      mov   ax,0fh                 ; FUNC 15: Mouse Hor/Vert resolution
  255.      mov   cx,4                   ; Horiz speed  >> Value => << Speed
  256.      mov   dx,8                   ; Vert Speed
  257.      int   33h
  258.  
  259.      mov   ax,3                   ; FUNC 3: Get mouse pos & button status
  260.      int   33h
  261.      mov   [_MouseY],dx
  262.      shr   cx,1
  263.      mov   [_MouseX],cx
  264.  
  265.      mov   ax,12                  ; FUNC 12: Define Event Handler
  266.      mov   bx,seg mouse_handler   ;  ES:DX -> Event handler
  267.      mov   es,bx
  268.      mov   dx,offset mouse_handler
  269.      mov   cx,1fh                 ;  Set handler for all events
  270.      int   33h
  271.  
  272.  
  273.  
  274.      mov   [_MouseHidden],TRUE    ; Mouse initially hidden
  275.  
  276.      push  ds                     ; Set the default cursor shape
  277.      mov   ax,offset InitMouseDef
  278.      push  ax
  279.      call  _x_define_mouse_cursor
  280.      add   sp,04h
  281.  
  282.      mov   ax,[_MouseInstalled]   ; Return MouseInstalled flag
  283. @@Done:
  284.      pop   bp
  285.      ret
  286. _x_mouse_init endp
  287.  
  288. ;----------------------------------------------------------------------
  289. ; x_mouse_window - Define a mouse window
  290. ;
  291. ; C Prototype
  292. ;
  293. ;  void x_mouse_window(int x0, int y0, int x1, int y1);
  294. ;
  295. ;
  296. ; Written by Themie Gouthas
  297. ;----------------------------------------------------------------------
  298. _x_mouse_window proc
  299. ARG x0:word,y0:word,x1:word,y1:word
  300.      push  bp
  301.      mov   bp,sp
  302.  
  303.      mov   ax,7       ; FUNC 7: Set X range
  304.      mov   cx,x0
  305.      shl   cx,1
  306.      mov   dx,x1
  307.      shl   dx,1
  308.      int   33h
  309.  
  310.      mov   ax,8       ; FUNC 8: Set Y range
  311.      mov   cx,y0
  312.      mov   dx,y1
  313.      int   33h
  314.      pop   bp
  315.      ret
  316. _x_mouse_window endp
  317.  
  318.  
  319. ;----------------------------------------------------------------------
  320. ; x_define_mouse_cursor - Define a mouse cursor from an input bitmask
  321. ;
  322. ; C Prototype
  323. ;
  324. ;  void x_define_mouse_cursor(char far *MouseDef, unsigned char MouseColor)
  325. ;
  326. ; WARNING: This function assumes MouseDef points to 14 bytes.
  327. ;
  328. ; Note: Bit order is in reverse. ie bit 7 represents pixel 0 ..
  329. ;       bit 0 represents pixel 7 in each "MouseDef" byte.
  330. ;
  331. ; Written by Themie Gouthas
  332. ;----------------------------------------------------------------------
  333. _x_define_mouse_cursor proc
  334. ARG MouseDef:dword,MouseColor:byte
  335.      push  bp
  336.      mov   bp,sp
  337.  
  338.      cmp  [_MouseInstalled],FALSE   ; Check whether we have installed
  339.      je   @@Done                    ;  our mouse handler and leave if not
  340.  
  341.      mov  al,[MouseColor]           ; Set the mouse pointers color
  342.      mov  [_MouseColor],al
  343.  
  344.      push  si
  345.      push  di
  346.      push  ds
  347.      mov   ax,ds                ; ES:DI -> Stored plane mask for all
  348.      mov   es,ax                ;   pixel alignments of mouse cursor
  349.      mov   di,offset MouseMask
  350.      lds   si,MouseDef
  351.      xor   cl,cl                ; CL = current alignment (initially zero)
  352. @@AlignmentLoop:
  353.      push  si                   ; save MouseDef ptr for next alignment
  354.      mov   dh,14                ; Init Row counter to Cursor Height
  355. @@RowLoop:
  356.      lodsb                      ; Load first cursor def byte each bit
  357.                 ;  representing pixel in the row
  358.      xor   ah,ah                ; AH is the shift overflow byte
  359.      shl   ax,cl                ; Shift mask for current alignment
  360.  
  361.      mov   bl,al                ; store first three nibbles of ax into
  362.      and   bl,0fh               ;  consecutive bytes in the destination
  363.      mov   es:[di],bl           ;  buffer
  364.      inc   di
  365.      shr   al,4
  366.      stosw
  367.  
  368.      dec   dh                   ; Next row for this alignment if there
  369.      jnz   @@RowLoop            ;  are more to do
  370.  
  371.      pop   si                   ; point to the start of the cursor def.
  372.      inc   cl                   ; Select next pixel alignment
  373.      cmp   cl,4                 ; If there are more alignments to do
  374.      jne   @@AlignmentLoop      ;   then jump
  375.  
  376.      pop   ds
  377.      pop   di
  378.      pop   si
  379. @@Done:
  380.      pop   bp
  381.      ret
  382. _x_define_mouse_cursor endp
  383.  
  384.  
  385. ;----------------------------------------------------------------------
  386. ; x_show_mouse - Shows a previously hidden mouse cursor
  387. ;
  388. ; C Prototype
  389. ;
  390. ;  void x_show_mouse()
  391. ;
  392. ; Written by Themie Gouthas
  393. ;----------------------------------------------------------------------
  394. _x_show_mouse proc
  395.      push  bp
  396.      mov   bp,sp
  397.      cmp   [_MouseInstalled],FALSE  ; Make sure our handler is installed
  398.      je    @@Done
  399.      cmp   [_MouseHidden],FALSE     ; If not hidden then exit
  400.      je    @@Done
  401.      push  si
  402.      push  di
  403.  
  404.  
  405. @@WaitEndOfHandler:               ; Make sure handler not currently active
  406.      mov   cl,[inhandler]
  407.      or    cl,cl
  408.      jnz   @@WaitEndOfHandler
  409.  
  410.  
  411.      mov   si,[_VisiblePageOffs]  ; Save mouse background and pos details
  412.      mov   ax,[_MouseY]
  413.      mov   bx,[_MouseX]
  414.      mov   [OldScrnOffs],si
  415.      mov   [OldY],ax
  416.      mov   [OldX],bx
  417.      call  getbg
  418.  
  419.      push [_VisiblePageOffs]      ; Draw cursor
  420.      push [_ScrnLogicalHeight]
  421.      xor  ax,ax
  422.      push ax
  423.      push [OldY]
  424.      push [OldX]
  425.      call _x_put_cursor
  426.      add  sp,10
  427.  
  428.      mov   [_MouseHidden],FALSE   ; Indicate mouse cursor no longer hidden
  429.  
  430.      pop  di
  431.      pop  si
  432. @@Done:
  433.      pop   bp
  434.      ret
  435. _x_show_mouse endp
  436.  
  437.  
  438. ;----------------------------------------------------------------------
  439. ; x_hide_mouse - Hides a previously visible mouse cursor
  440. ;
  441. ; C Prototype
  442. ;
  443. ;  void x_hide_mouse()
  444. ;
  445. ; Written by Themie Gouthas
  446. ;----------------------------------------------------------------------
  447. _x_hide_mouse proc
  448.      push  bp
  449.      mov   bp,sp
  450.  
  451.      cmp   [_MouseInstalled],FALSE   ; Make sure our handler is installed
  452.      je    @@Done
  453.      cmp   [_MouseHidden],FALSE      ; If cursor is already hidden exit
  454.      jne   @@Done
  455.      push  si
  456.      push  di
  457.  
  458. @@WaitEndOfHandler:            ; Make sure handler not currently active
  459.      mov   cl,[inhandler]
  460.      or    cl,cl
  461.      jnz   @@WaitEndOfHandler
  462.  
  463.      mov   [_MouseHidden],TRUE       ; Delete mouse cursor
  464.      mov   di,[OldScrnOffs]
  465.      mov   ax,[OldY]
  466.      mov   bx,[OldX]
  467.      call  restorebg
  468.      pop   di
  469.      pop   si
  470. @@Done:
  471.      pop   bp
  472.      ret
  473. _x_hide_mouse endp
  474.  
  475.  
  476. ;----------------------------------------------------------------------
  477. ; x_remove_mouse - removes mouse handler
  478. ;
  479. ; C Prototype
  480. ;
  481. ;  void x_remove_mouse()
  482. ;
  483. ; NOTE: This function MUST be called before quitting the program if
  484. ;       a mouse handler has been installed
  485. ;
  486. ; Written by Themie Gouthas
  487. ;----------------------------------------------------------------------
  488. _x_mouse_remove proc
  489.     push  bp
  490.     mov   bp,sp
  491.     cmp   [_MouseInstalled],FALSE  ; Check whether we have installed
  492.     je    @@Done                   ;  our mouse handler
  493.     call  _x_hide_mouse
  494.     mov   ax,12                    ; FUNC 12: Install event handler
  495.     xor   cx,cx                    ; Disable all events
  496.     int   33h
  497.     mov   [_MouseInstalled],FALSE
  498. @@Done:
  499.     pop   bp
  500.     ret
  501. _x_mouse_remove endp
  502.  
  503.  
  504. ;----------------------------------------------------------------------
  505. ; x_position_mouse - Positions the mouse cursor at the specified location
  506. ;
  507. ; C Prototype
  508. ;
  509. ;  void x_position_mouse(int x, int y)
  510. ;
  511. ;
  512. ; Written by Themie Gouthas
  513. ;----------------------------------------------------------------------
  514. _x_position_mouse proc
  515. ARG  X:word,Y:word
  516.      push  bp
  517.      mov   bp,sp
  518.  
  519. @@WaitEndOfHandler:               ; Make sure handler not currently active
  520.      mov   bl,[inhandler]
  521.  
  522.      or    bl,bl
  523.      jnz   @@WaitEndOfHandler
  524.  
  525.      mov   ax,4
  526.      mov   cx,X
  527.      mov   dx,Y
  528.      mov   [_MouseX],cx
  529.      mov   [_MouseY],dx
  530.      shl   cx,1
  531.  
  532.      mov   [inhandler],1
  533.      int   33h
  534.  
  535.      ; The handler doesnt get called so need
  536.      ; to update manually;
  537.  
  538.      cmp   [_MouseHidden],FALSE
  539.      jne   @@NotVisible
  540.      push  di si
  541.      call  update_cursor
  542.      pop   si di
  543.  
  544. @@NotVisible:
  545.      mov   [inhandler],0
  546.      pop   bp
  547.      ret
  548. _x_position_mouse endp
  549.  
  550. ;----------------------------------------------------------------------
  551. ; x_update_mouse - Forces the mouse position to be updated and cursor
  552. ;                  to be redrawn.
  553. ;
  554. ; C Prototype
  555. ;
  556. ;  void x_update_mouse()
  557. ;
  558. ; Note this function is useful when you have set "MouseFrozen" to true.
  559. ; Allows the cursor position to be updated manually rather than
  560. ; automatically by the installed handler.
  561. ;
  562. ;
  563. ; Written by Themie Gouthas
  564. ;----------------------------------------------------------------------
  565. _x_update_mouse proc
  566.      push  bp
  567.      mov   bp,sp
  568.      cmp   [_MouseInstalled],FALSE   ; Make sure our handler is installed
  569.      je    @@Done
  570.      cmp   [_MouseHidden],FALSE      ; If cursor is already hidden exit
  571.      jne   @@Done
  572.      push  si
  573.      push  di
  574.      mov   ax,03h                 ; FUNC 3: get cursor pos / button status
  575.      int   33h                    ; Update position variables first
  576.      shr   cx,1
  577.      mov   [_MouseX],cx
  578.      mov   [_MouseY],dx
  579.      mov   [_MouseButtonStatus],bx    ; Update button status
  580.      call  update_cursor
  581.      pop   di
  582.      pop   si
  583. @@Done:
  584.      pop   bp
  585.      ret
  586. _x_update_mouse endp
  587.  
  588.  
  589. ;----------------------------------------------------------------------
  590. ; x_put_cursor - Draws the mouse cursor
  591. ;
  592. ; C Prototype
  593. ;
  594. ; void x_put_cursor(int X, int Y, int TopClip, int BottomClip, WORD ScrnOffs)
  595. ;
  596. ;
  597. ; Written by Themie Gouthas
  598. ;----------------------------------------------------------------------
  599. ALIGN 2
  600. _x_put_cursor  proc
  601. ARG X:word,Y:word,TopClip,BottomClip,ScrnOffs
  602. LOCAL Height,TopRow,NextLineIncr:word=LocalStk
  603.     push  bp
  604.     mov   bp,sp
  605.     sub   sp,LocalStk                 ; Create space for local variables
  606.     push  si
  607.     push  di
  608.     push  ds
  609.     mov   ax,@data
  610.     mov   ds,ax
  611.     cld
  612.  
  613.     mov   ax,14                   ; Get image height and save in AX
  614.     mov   bx,Y
  615.     ; cx = top Row
  616.  
  617.     ;;;;; CLIP PROCESSING FOR TOP CLIP BORDER ;;;;;;;;;;;;;;;;;;;;;
  618.  
  619.     mov   dx,[TopClip]            ; Compare u.l. Y coord with Top
  620.     sub   dx,bx                   ; clipping border
  621.     jle   @@NotTopClip            ; jump if  not clipped from above
  622.     cmp   dx,ax
  623.     jnl   @@NotVisible            ; jump if  is completely obscured
  624.     mov   cx,dx
  625.     sub   ax,dx
  626.     add   bx,dx
  627.     jmp   short @@VertClipDone
  628.  
  629.     ;;;; EXIT FOR COMPLETELY OBSCURED  ;;;;;;;;;;;;;;;;;;;;;;
  630.  
  631. @@NotVisible:
  632.     pop   ds
  633.     pop   di                          ; restore registers
  634.     pop   si
  635.     mov   sp,bp                       ; dealloc local variables
  636.     pop   bp
  637.     ret
  638.  
  639.     ;;;;; CLIP PROCESSING FOR BOTTOM CLIP BORDER ;;;;;;;;;;;;;;;;;;;
  640.  
  641. @@NotTopClip:
  642.     mov   dx,[BottomClip]
  643.     sub   dx,bx
  644.     js    @@NotVisible
  645.     mov   cx,0
  646.     cmp   dx,ax
  647.     jg    @@VertClipDone
  648.     inc   dx
  649.     mov   ax,dx
  650.  
  651. @@VertClipDone:
  652.  
  653.     mov   [Height],ax
  654.     mov   [TopRow],cx
  655.  
  656.     mov   ax,SCREEN_SEG               ; Point es to VGA segment
  657.     mov   es,ax
  658.  
  659.     mov   ax,bx
  660.     mov   cx,[_ScrnLogicalByteWidth]  ; Find required screen address
  661.     mul   cx
  662.     mov   di,ax
  663.  
  664.     sub   cx,3                        ; Distance to next screen row
  665.     mov   [NextLineIncr],cx
  666.  
  667.  
  668.     mov   cx,[X]
  669.     mov   bx,cx
  670.     shr   cx,2
  671.     add   di,cx
  672.     and   bx,3
  673.     add   di,[ScrnOffs]
  674.  
  675.     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  676.  
  677.  
  678.     mov   ax,42
  679.     mul   bx
  680.     mov   si,offset MouseMask
  681.     add   si,ax
  682.  
  683.     mov   ax,3                        ; Increment DS:BX and DS:SI to
  684.     mul   [TopRow]                    ;  been clipped by the top border
  685.     add   si,ax                       ; by the L.H.S border
  686.  
  687.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  688.     mov   al,MAP_MASK                 ; in preperation for masking data
  689.     out   dx,al
  690.     inc   dx                          ; Point dx to SC data register
  691.     mov   ah,byte ptr [Height]        ; AH = Scanline loop counter
  692.     mov   bl,[_MouseColor]
  693. @@RowLoop:
  694.     mov   cx,3                        ; Width in bytes across
  695. @@ColLoop:
  696.     lodsb                             ; load plane mask and set MAP MASK
  697.     out   dx,al
  698.     mov   es:[di],bl                  ; store color to specified planes
  699.     inc   di
  700.     loop  @@ColLoop
  701.  
  702.     add   di,[NextLineIncr]
  703.     dec   ah
  704.     jnz   @@RowLoop
  705.  
  706.     pop   ds
  707.     pop   di                          ; restore registers
  708.     pop   si
  709.     mov   sp,bp                       ; dealloc local variables
  710.     pop   bp
  711.     ret
  712. _x_put_cursor  endp
  713.  
  714.  
  715. ;----------------------------------------------------------------------
  716. ; getbg - saves cursor background
  717. ;
  718. ; C Prototype
  719. ;
  720. ; local function using register parameters
  721. ;
  722. ; si = screen offset
  723. ; ax  = y
  724. ; bx  = x
  725. ;
  726. ; Written by Themie Gouthas
  727. ;----------------------------------------------------------------------
  728. ALIGN 2
  729. getbg  proc near
  730.  
  731.     push  bp
  732.     mov   bp,sp
  733.     push  ds
  734.     cld
  735.  
  736.     mov   cx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  737.     mul   cx                          ;  width then adding screen offset
  738.     add   si,ax                       ; Add Dest Screen Row to di
  739.     sub   cx,3
  740.     shr   bx,2
  741.     add   si,bx
  742.     mov   bx,cx
  743.  
  744.     mov   di,BGSaveOffs
  745.     mov   ax,SCREEN_SEG               ; Point es to VGA segment
  746.     mov   es,ax
  747.     mov   ds,ax
  748.  
  749.     mov   dx,GC_INDEX                 ; Set bit mask for all bits from
  750.     mov   ax,BIT_MASK                 ; VGA latches and none from CPU
  751.     out   dx,ax
  752.  
  753.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  754.     mov   al,MAP_MASK           ; in preperation for masking data
  755.     out   dx,al
  756.     inc   dx
  757.     mov   al,0fh
  758.     out   dx,al
  759.  
  760.     mov   cx,14
  761. @@Loop:
  762.     movsb
  763.     movsb
  764.     movsb
  765.     add si,bx
  766.     loop @@Loop
  767.  
  768. mov     dx,GC_INDEX+1 ;restore the bit mask to its default,
  769.     mov     al,0ffh       ; which selects all bits from the CPU
  770.     out     dx,al         ; and none from the latches (the GC
  771.                   ; Index still points to Bit Mask)
  772.  
  773.     pop   ds
  774.     mov   sp,bp                       ; dealloc local variables
  775.     pop   bp
  776.     ret
  777. getbg  endp
  778.  
  779. ;----------------------------------------------------------------------
  780. ; restorebg - restores cursor background
  781. ;
  782. ; C Prototype
  783. ;
  784. ; local function using register parameters
  785. ;
  786. ; di = screen offset
  787. ; ax  = y
  788. ; bx  = x
  789. ;
  790. ; Written by Themie Gouthas
  791. ;----------------------------------------------------------------------
  792. ALIGN 2
  793. restorebg  proc near
  794. ;di = scrn offs
  795. ;ax  = y
  796. ;bx  = x
  797.     push  bp
  798.     mov   bp,sp
  799.     push  ds
  800.     cld
  801.  
  802.     mov   cx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  803.     mul   cx                          ;  width then adding screen offset
  804.     add   di,ax                       ; Add Dest Screen Row to di
  805.     sub   cx,3
  806.     shr   bx,2
  807.     add   di,bx
  808.     mov   si,BGSaveOffs
  809.     mov   ax,SCREEN_SEG               ; Point es to VGA segment
  810.     mov   es,ax
  811.     mov   ds,ax
  812.  
  813.     mov   dx,GC_INDEX                 ; Set bit mask for all bits from
  814.     mov   ax,BIT_MASK                 ; VGA latches and none from CPU
  815.     out   dx,ax
  816.  
  817.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  818.     mov   al,MAP_MASK                 ; in preperation for masking data
  819.     out   dx,al
  820.     inc   dx
  821.     mov   al,0fh
  822.     out   dx,al
  823.  
  824.     mov   bx,cx
  825.     mov   cx,14
  826. @@Loop:
  827.     movsb
  828.     movsb
  829.     movsb
  830.     add di,bx
  831.     loop @@Loop
  832.     mov  dx,GC_INDEX+1 ;restore the bit mask to its default,
  833.     mov  al,0ffh       ; which selects all bits from the CPU
  834.     out  dx,al         ; and none from the latches (the GC
  835.                ; Index still points to Bit Mask)
  836.     pop   ds
  837.     pop   bp
  838.     ret
  839. restorebg  endp
  840.  
  841.  
  842.  
  843. ;********************** The Mouse event handler *************************
  844.  
  845. ALIGN 2
  846. mouse_handler proc far
  847.    push  bp
  848.    mov   bp,sp
  849.    push  ds
  850.  
  851.    mov   di,@data                   ; Make sure DS points to data segment
  852.    mov   ds,di
  853.    cmp   [inhandler],1
  854.    jne   @@NotActive
  855.    pop   ds
  856.    pop   bp
  857.    ret
  858.  
  859. @@NotActive:
  860.    mov   [inhandler],1
  861.    mov   [_MouseButtonStatus],bx    ; Update button status
  862.    test  ax,1                       ; Is this a motion event ?
  863.    jz    @@Done                     ; No Jump
  864.  
  865.    shr  cx,1                        ; convert X coord to pixel coords
  866.    mov  [_MouseX],cx                ; save mouse position
  867.    mov  [_MouseY],dx
  868.  
  869.    cmp  [_MouseHidden],TRUE         ; If mouse hidden dont bother drawing
  870.    je   @@Done
  871.  
  872.    cmp  [_MouseFrozen],TRUE         ; If mouse hidden dont bother drawing
  873.    je   @@Done
  874.  
  875.    call update_cursor
  876. @@Done:
  877.    mov  [inhandler],0
  878.    pop  ds
  879.    pop  bp
  880.    ret
  881. mouse_handler endp
  882.  
  883.  
  884. end
  885.